<template>
  <div class="app-container">
         <el-table v-loading="loading" :data="productList" @selection-change="handleSelectionChange">
            <el-table-column type="selection" width="55" align="center" />
            <el-table-column label="产品名称" align="center" prop="name" />
            <el-table-column label="产品编码" align="center" prop="code" />
            <el-table-column label="单位" align="center" prop="unit" />
            <el-table-column label="价格" align="center" prop="price" width="120px">
                <template slot-scope="scope">
                  <span class="money">{{formatMoney(scope.row.price,',')}}</span>
                </template>
            </el-table-column>
            <el-table-column label="分类" align="center" prop="cateName" />
         </el-table>
          <pagination
            v-show="total>0"
            :total="total"
            :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize"
            @pagination="getList"
          />
          <div slot="footer" class="dialog-footer">
            <el-button type="primary" @click="submitForm">确 定</el-button>
          </div>
  </div>
</template>

<script>

import { getSalelist, getProduct, delProduct, addProduct, updateProduct, exportProduct } from "@/api/crm/product";

export default {
  name: "Product",
  components: {  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 产品表格数据
      productList: [],
       queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
    };
  },
  created() {
      this.getList();
  },
  mounted() {
   
  },
  methods: {
    submitForm(){
      var list=[];
      for(var i=0;i<this.productList.length;i++){
          for(var k=0;k<this.ids.length;k++){
            if(this.productList[i].productId==this.ids[k]){
              list.push(this.productList[i]);
            }
          }
      }
      this.$emit('update-product',list);

    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.productId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    getList() {
      this.loading = true;
      getSalelist(this.queryParams).then(response => {
        this.productList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    getContract(contractId){
      getContract(contractId,1).then(response => {
        this.contract = response.contract;
        this.productList=response.product;
        this.customer=response.customer;
      
      });
    }
    
  }
};
</script>
<style scoped>
 .dialog-footer{
   margin-top: 30px;
   float: right;
 }
</style>

